package one;

public class Work1_StudentObj {
    private int id;
    private String name;
    private int age;

    public Work1_StudentObj() {
    }

    public Work1_StudentObj(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) throws IdException {
        if(id > 0){
            this.id = id;
        }else{
            throw new IdException("学号不合理哦！");//对学号进行合理值的判断
        }

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws AgeException {
        if(age < 150 && age > 0){
            this.age = age;
        }else{
            throw new AgeException("年龄不对哦！！"); //对年龄进行合理值的判断
        }

    }

    @Override//重写toString方法，打印显示学生信息
    public String toString() {
        return "学生"+id+"[id=" + id + ", name=" + name + ", age=" + age + ']';
    }

}